# Dockerfile
# 使用Python官方镜像作为基础
FROM python:3.8-slim

# 设置工作目录
WORKDIR /app

# 安装系统依赖
RUN apt-get update && apt-get install -y \
    libgl1 \
    libglib2.0-0 \
    && rm -rf /var/lib/apt/lists/*

# 复制并安装Python依赖
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# 复制应用代码
COPY app ./app

# 设置环境变量
ENV PYTHONPATH=/app
ENV PORT=8000
ENV UVICORN_WORKERS=2

# 预下载模型（加速首次请求）
RUN python -c "from rembg import new_session; new_session('u2net_human_seg')"

# 暴露端口
EXPOSE $PORT

# 启动命令
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "$PORT", "--workers", "$UVICORN_WORKERS"]